package com.gitee.neuray.security.generator.databasemd.controller;

import cn.hutool.core.exceptions.ExceptionUtil;
import com.gitee.neuray.security.common.msg.ObjectRestResponse;
import org.springframework.web.bind.annotation.*;
import com.gitee.neuray.security.common.rest.BaseController;

import com.gitee.neuray.security.generator.databasemd.entity.TDatabaseInfoEntity;
import com.gitee.neuray.security.generator.databasemd.biz.TDatabaseInfoBiz;



/**
 * 代码生成器-数据库信息
 *
 * @author zhhongyu
 * @email ${email}
 * @date 2020-01-08 16:40:58
 */
@RestController
@RequestMapping("databasemd")
public class TDatabaseInfoController extends BaseController<TDatabaseInfoBiz, TDatabaseInfoEntity>{
    /**
     * 测试数据库连接
     * @return
     */
    @RequestMapping(value = "/dbtest/{id}",method = RequestMethod.GET)
    public ObjectRestResponse<Boolean> dbtest(@PathVariable String id){
        ObjectRestResponse objectRestResponse = new ObjectRestResponse();
        try{
            TDatabaseInfoEntity tDatabaseInfoEntity = baseBiz.selectById(id);
            boolean dbtest = baseBiz.dbtest(tDatabaseInfoEntity);
            return objectRestResponse.data(dbtest).rel(dbtest);
        }catch (Exception e){
            return objectRestResponse.data(false).rel(false).msg(ExceptionUtil.getMessage(e));
        }
    }
}
